<?php

/**
 * @author @author Samrat Khan & Sadik Sarfaraz - Apr 13, 2013
 */

    require('top.inc.php');
?>
<?php
if(isset($_SESSION['user']) && $_SESSION['user']['utype'] == 1 || $_SESSION['user']['utype'] == 2 || $_SESSION['user']['utype'] == 3 || $_SESSION['user']['utype'] == 4) {
    $sess_cusID = $_SESSION['user']['cus_id'];
    //$rows = selectAll('DESC', 'inserteddate', faulty_export, $db);
    
    echo '<div class="fixedleftBox">';
        echo "<input class=\"btn btn-primary\" type=\"button\" onclick=\"tableToExcel('faultyExportTable', 'Faulty Export Table History')\" value=\"Export to excel\">";
    echo '</div>';
    
    //create new object pass in number of pages and identifier
    $pages = new Paginator(' 50', 'page');
    $total = getCountA('faulty_export', 'faulty_export_id', 'cus_id', $sess_cusID, $db);
    $tots = $total[0]['total'];
    $totals = $pages->set_total($tots);
    $limit = $pages->get_limit();
    
    $rows = selectAllWhereA('faulty_export', $limit, 'cus_id', $sess_cusID, $db);
    
    echo "<h5>Faulty Export Report</h5>";
    echo "<table id=\"faultyExportTable\" class=\"row-fluid table table-striped table-bordered\">";
            echo "<tr>";
                echo "<th>" . $faulty_export['serialno'] . "</th>";
                echo "<th>" . $faulty_export['project_id'] . "</th>";
                echo "<th>" . $faulty_export['productid'] . "</th>";
                echo "<th>" . $faulty_export['description'] . "</th>";
                echo "<th>" . $faulty_export['revisionstate'] . "</th>";
                echo "<th>" . $faulty_export['boxno'] . "</th>";
                echo "<th>" . $faulty_export['uom'] . "</th>";
                echo "<th>" . $faulty_export['faulty_export_quantity'] . "</th>";
                echo "<th>" . $faulty_export['handedoverto'] . "</th>";
                echo "<th>" . $faulty_export['manufacturingdate'] . "</th>";
                echo "<th>" . $faulty_export['faultydocketnumber'] . "</th>";
                echo "<th>" . $faulty_export['docketdate'] . "</th>";
                echo "<th>" . $faulty_export['siteid'] . "</th>";
                echo "<th>" . $faulty_export['warehouse_id'] . "</th>";
                echo "<th>" . $faulty_export['wh_rma'] . "</th>";
                echo "<th>" . $faulty_export['bd_rma'] . "</th>";
                echo "<th>" . $faulty_export['export_rma'] . "</th>";
                echo "<th>" . $faulty_export['rr_invoiceno'] . "</th>";
                echo "<th>" . $faulty_export['rr_date'] . "</th>";
                echo "<th>" . $faulty_export['rr_mawb'] . "</th>";
                echo "<th>" . $faulty_export['rr_awb'] . "</th>";
                echo "<th>" . $faulty_export['remarks'] . "</th>";
                echo "<th>" . $faulty_export['userid'] . "</th>";
                echo "<th>" . $customer_info['cusname'] . "</th>";
                echo "<th>" . $faulty_export['inserteddate'] . "</th>";
            echo "</tr>";
            
        foreach ($rows as $row) {
            echo "<tr>";
                echo "<td>". $row['serialno'] ."</td>";
                echo "<td>";
                    echo getName('projects', 'projectname', 'project_id', $row['project_id'], $db);
                    echo "<br/>";
                    $idofcustomer = getName('projects', 'cus_id', 'project_id', $row['project_id'], $db);
                    $customerid = getName('customerinfo', 'cus_id', 'cus_id', $idofcustomer, $db);
                echo "</td>";
                echo "<td>". $row['productid'] ."</td>";
                echo "<td>". $row['description'] ."</td>";
                echo "<td>". $row['revisionstate'] ."</td>";
                echo "<td>". $row['boxno'] ."</td>";
                echo "<td>". getName('uom', 'measurement', 'uom_id', $row['uom'], $db)  ."</td>";
                echo "<td>". $row['faulty_export_quantity'] ."</td>";
                echo "<td>". $row['handedoverto'] ."</td>";
                echo "<td>". $row['manufacturingdate'] ."</td>";
                echo "<td>". $row['faultydocketnumber'] ."</td>";
                echo "<td>". $row['docketdate'] ."</td>";
                echo "<td>". $row['siteid'] ."</td>";
                echo "<td>". getName('warehouses', 'warehousename', 'warehouse_id', $row['warehouse_id'], $db) ."</td>";
                echo "<td>". $row['wh_rma'] ."</td>";
                echo "<td>". $row['bd_rma'] ."</td>";
                echo "<td>". $row['export_rma'] ."</td>";
                echo "<td>". $row['rr_invoiceno'] ."</td>";
                echo "<td>". $row['rr_date'] ."</td>";
                echo "<td>". $row['rr_mawb'] ."</td>";
                echo "<td>". $row['rr_awb'] ."</td>";
                echo "<td>". $row['remarks'] ."</td>";
                echo "<td>". getName('wms_users', 'username', 'id', $row['userid'], $db) ."</td>";
                echo "<td>". getName('customerinfo', 'cusname', 'cus_id', $row['cus_id'], $db) ."</td>";
                echo '<input type="hidden" name="session_id" value="'.  session_id() .'" />';
                echo '<input type="hidden" name="junkentry" value="0" />';
                echo "<td>". $row['inserteddate'] ."</td>";
            echo "</tr>";
        }
    echo "<table>";
    echo $pages->page_links();
} else {
    header("Location: login.php");
}
?>

<?php
    include ('bottom.inc.php');
?>